//package com.springboot.auth.Interceptor;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.Arrays;
//import java.util.Map;
//import java.util.stream.Collectors;
//
//@Component
//@Slf4j
//public class LogInterceptor extends HandlerInterceptorAdapter {
//
//    /**
//     * 登录前执行。
//     *
//     * @param request
//     * @param response
//     * @param handler
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        long startTime = System.currentTimeMillis();
//        log.info("\n\n-------- LogInterceptor.preHandle --- "
//                + "\nRequest URL: " + request.getRequestURL()
//                + "\nStart Time: " + System.currentTimeMillis() + "\n");
//
//        System.out.println("handler = " + handler);
////
////        // 获取请求参数
////        Map<String, String[]> parameterMap = request.getParameterMap();
////        // 获取@RequestBody参数
////        String requestBody = request.getReader().lines().collect(Collectors.joining());
////
////        System.out.println("========================");
////        for (Map.Entry <String, String[]>  entry : parameterMap.entrySet()) {
////            System.out.println("Key = " + entry.getKey() + ", Value = " + Arrays.toString(entry.getValue()));
////
////        }
////        System.out.println("======================");
////        System.out.println("requestBody = " + requestBody);
////        // 对请求参数和@RequestBody参数进行处理
////
////        request.setAttribute("startTime", startTime);
//
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//        log.info("\n\n-------- LogInterceptor.postHandle --- "
//                + "\nRequest URL: " + request.getRequestURL() + "\n");
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        log.info("\n\n-------- LogInterceptor.afterCompletion --- ");
//
//        long startTime = (Long) request.getAttribute("startTime");
//        long endTime = System.currentTimeMillis();
//        log.info("Request URL: " + request.getRequestURL()
//                + "\nEnd Time: " + endTime
//                + "\nTime Taken: " + (endTime - startTime) + "\n");
//    }
//}
